tm = TestManager()
stage.set_axis(0,14)
""" ONLY CHANGE WHAT IS BETWEEN THE GREEN DASHES:
---------------------------------------------------------------"""
# This array represents the board.
# 1's are blocks and 0's are open pathways.
maze_data = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]
# This is where the turtle starts.
start_position = (6, 6.5)
# This is where the goal is.
goal_position = (12, 6.5)
# This is the direction the turtle points to begin with
start_direc = 0
# This is the scale factor for the blocks.
block_size = 1
end_result = "incomplete"
# This function iterates through the maze_data array and draws the squares.
def draw_board():
board = maze_data
for j in range(len(board)):
for i in range(len(board[j])):
if board[j][i] == 1:
block_x = (i + 0.5) * block_size + 2
block_y = (j + 0.5) * block_size + .5
block = codesters.Square(block_x, block_y, block_size, "sienna", "black")
else:
block_x = (i + 0.5) * block_size + 2
block_y = (j + 0.5) * block_size + .5
block = codesters.Square(block_x, block_y, block_size, None, "black")
# This function creates a goal block at the specified position.
def create_goal():
goal_x = (goal_position[0] - 0.5) * block_size
goal_y = (goal_position[1] - 0.5) * block_size
goal_block = codesters.Square(goal_x, goal_y, block_size, "gold", "black")
# This is the main program. It calls the three principal functions,
# creates the turtle, and puts it on the screen
# This calls the function to draw the goal
# This line calls the function to draw the whole board
draw_board()
create_goal()
sprite = codesters.Sprite("hedgehog")
sprite.set_size(0.3)
sprite.set_speed(2)
# This function puts the turtle at the starting position and rotation.
def send_sprite_home(t):
t.set_x((start_position[0] - 0.5 ))
t.set_y((start_position[1] - .5) * block_size)
t.turn_left(start_direc)
send_sprite_home(sprite)
txt = codesters.Text("Here is a smaller version of our maze!", 7, 12, "black")
background = codesters.Rectangle(7, 10, 13, 2, "black")
num_line = codesters.Line(1, 9, 1, 11, "gray")
y_text = 10.50
x_text = 7
y_var = y_text
y_text = y_var
for counter in range(3):
nums = codesters.Text(str(counter+4), .75, y_var, "gray")
nums.set_size(.9)
y_var -= .6
start_rect = codesters.Rectangle(7, 12, 13, 2, "green")
start_text = codesters.Text("Click this button to start the demo.", 7, 12, "white")
def show_button():
start_rect.show()
start_text.show()
def hide_button():
start_rect.hide()
start_text.hide()
line1 = codesters.Text("sprite", x_text - 5, y_text, "orange")
line1a = codesters.Text("= codesters.Sprite( )", x_text - .5, y_text, "white")
line1b = codesters.Text('"hedgehog"', x_text + 1.55, y_text, "limegreen")
line1_hl = codesters.Rectangle(x_text-1, y_text, 10, 1, None, "yellow")
line1_hl.hide()
lines_1 = [line1, line1a, line1b]
for line in lines_1:
line.set_size(.9)
# line.hide()
y_text-=.6
line2 = codesters.Text("sprite", x_text-5, y_text, "orange")
line2a = codesters.Text(".move_forward( )", x_text - 2, y_text, "white")
hl = codesters.Square(x_text - .3, y_text,.7, None, "yellow")
hl.hide()
line2b = codesters.Text('50', x_text -.3 , y_text, "cornflowerblue")
line2_hl = codesters.Rectangle(x_text-1, y_text-.2, 10, 1, None, "yellow")
line2_hl.hide()
lines_2 = [line2, line2a, line2b]
for line in lines_2:
line.set_size(.9)
line.hide()
def click_1():
hide_button()
txt.set_text("This is the line of code that creates the hedgehog sprite.")
line1_hl.show()
for line in lines_1:
line.show()
start_rect.move_down(10.5)
start_text.move_down(10.5)
show_button()
start_text.set_text("Click here to program the hedgehog to move.")
def click_2():
line1_hl.hide()
hide_button()
txt.set_text("This line of code tells the sprite to move forward.")
line2_hl.show()
for line in lines_2:
line.show()
start_text.set_text("Click to run the program.")
show_button()
def click_3():
line2_hl.hide()
hide_button()
sprite.move_forward(20)
txt.set_text("Oh no! Our sprite moved all the way off the stage!")
start_text.set_text("Click to fix the program.")
show_button()
def click_4():
hide_button()
send_sprite_home(sprite)
txt.set_text("The number in the .move_forward() command controls the distance the sprite will move.")
start_text.set_text("Click to change the number in the .move_forward() command.")
show_button()
def click_5():
hide_button()
txt.set_text("We want the hedgehog to move 6 spaces, so we'll change the number in the command to 6.")
hl.show()
line2b.set_text(6)
start_text.set_text("Click to move the hedgehog 6 spaces forward.")
show_button()
def click_6():
hide_button()
move = 1
line2b.set_text('6')
for counter in range(6):
sprite.move_forward(1)
sprite.say(move, .7, "cornflowerblue", 30)
sprite.say(move)
move+=1
click_num = 1
def router():
global click_num
if click_num == 1:
click_1()
elif click_num == 2:
click_2()
elif click_num == 3:
click_3()
elif click_num == 4:
click_4()
elif click_num == 5:
click_5()
elif click_num == 6:
click_6()
txt.set_text("Click submit and next to move on.")
tm.display_success_message("Great job!")
else:
txt.set_text("Click submit and next to move on.")
tm.display_success_message("Great job!")
click_num +=1
start_rect.event_click(router)